package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.TeamInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.TeamInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.crm.jdy.service.client.TeamInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 团队信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月26日
*
*/
@Validated
@Api(tags = "teamInfo", description ="团队信息")
@RestController
@RequestMapping("/teamInfo")
public class TeamInfoController{

    @Reference(version = "${service.version}", check = false)
    TeamInfoService teamInfoService;

    @RateLimit()
    @ApiOperation("团队信息")
    @PostMapping("/seleteTeamInfo")
    public ResultVo seleteTeamInfo( @RequestBody TeamInfoDto teamInfoDto){
        PageInfo<TeamInfo> list = teamInfoService.seleteTeamInfo(teamInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新团队信息")
    @PostMapping("/updatTeamInfo")
    public ResultVo updateTeamInfo(@ApiParam(value = "teamInfo", required = true)
                                   @Validated @RequestBody TeamInfo teamInfo){
        boolean index = teamInfoService.updateTeamInfo(teamInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加团队信息")
    @PostMapping("/addTeamInfo")
    public ResultVo addTeamInfo(@ApiParam(name = "teamInfo", required = false)
                                @Validated @RequestBody TeamInfo teamInfo){
        boolean list  = teamInfoService.addTeamInfo(teamInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除团队信息")
    @DeleteMapping("deleteTeamInfo/{teamId}")
    public ResultVo deleteTeamInfo(@NotNull @ApiParam(name = "teamId", value = "teamId", required = true) @PathVariable String teamId){
        boolean b = teamInfoService.removeTeamInfo(teamId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}